<template>
  <div class="card-container" :style="cardStyle" :class="{ 'card-hover': hover }" @mouseenter="hover = true" @mouseleave="hover = false">
    <div class="card-header">
      <div class="title-wrapper">
        <i :class="icon" class="title-icon"></i>
        <span class="title">{{title}}</span>
      </div>
      <el-tooltip :content="tooltipContent" placement="top" effect="light">
        <svg t="1637478175000" class="info-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
          p-id="2179" width="16" height="16">
          <path
            d="M536 480v192a16 16 0 0 1-16 16h-16a16 16 0 0 1-16-16V480a16 16 0 0 1-16-16h16a16 16 0 0 1 16 16z m-32-128h16a16 16 0 0 1 16 16v32a16 16 0 0 1-16 16h-16a16 16 0 0 1-16-16v-32a16 16 0 0 1 16-16z m8 448c159.056 0 288-128.944 288-288s-128.944-288-288-288-288 128.944-288 288 128.944 288 288 288z m0 48c-185.568 0-336-150.432-336-336s150.432-336 336-336 336 150.432 336 336-150.432 336-336 336z"
            p-id="2180" :fill="iconColor"></path>
        </svg>
      </el-tooltip>
    </div>
    
    <div class="card-content">
      <div class="count-wrapper">
        <span class="count-number" :style="gradientStyle">{{formatNumber(count)}}</span>
        <span class="count-trend" v-if="trend" :class="trend > 0 ? 'trend-up' : 'trend-down'">
          <i :class="trend > 0 ? 'el-icon-top' : 'el-icon-bottom'"></i>
          {{Math.abs(trend)}}%
        </span>
      </div>
    </div>
    
    <div class="card-charts">
      <slot name="charts"></slot>
    </div>
    
    <div class="card-footer">
      <slot name="footer">
        <div class="footer-feishu">
          <div class="footer-item">
            <span class="footer-label">
              <i class="el-icon-time"></i>
              较昨日
            </span>
            <div class="footer-value-wrapper">
              <span class="footer-value" :class="trend > 0 ? 'trend-up' : 'trend-down'">
                {{trend > 0 ? '+' : ''}}{{trend}}%
              </span>
              <i :class="trend > 0 ? 'el-icon-top' : 'el-icon-bottom'"></i>
            </div>
          </div>
          <div class="footer-divider"></div>
          <div class="footer-item">
            <span class="footer-label">
              <i class="el-icon-refresh"></i>
              更新时间
            </span>
            <span class="footer-value">{{timeValue}}</span>
          </div>
        </div>
      </slot>
    </div>
    
    <div class="card-decoration" :style="{ backgroundColor: bgColor }"></div>
    <div class="card-pattern"></div>
  </div>
</template>

<script>
export default {
  name: 'Detail',
  props: {
    title: {
      type: String,
      required: true
    },
    count: {
      type: [Number, String],
      required: true
    },
    trend: {
      type: Number,
      default: 0
    },
    color: {
      type: String,
      default: '#1890ff'
    },
    cardType: {
      type: String,
      default: 'default'
    },
    timeValue: {
      type: String,
      default: '刚刚更新'
    },
    icon: {
      type: String,
      default: 'el-icon-data-line'
    }
  },
  data() {
    return {
      hover: false
    }
  },
  computed: {
    tooltipContent() {
      return `显示${this.title}的统计数据，包括当前值和变化趋势`
    },
    textColor() {
      return this.hover ? this.color : '#333'
    },
    iconColor() {
      return this.hover ? this.color : '#8a8a8a'
    },
    bgColor() {
      return this.color
    },
    gradientStyle() {
      return {
        background: `linear-gradient(45deg, ${this.color}, #333)`,
        WebkitBackgroundClip: 'text',
        WebkitTextFillColor: this.hover ? 'transparent' : 'inherit',
        transition: 'all 0.3s cubic-bezier(0.4, 0, 0.2, 1)'
      }
    },
    cardStyle() {
      if (this.cardType === 'gradient') {
        return {
          background: `linear-gradient(135deg, ${this.color}15 0%, ${this.color}30 100%)`,
          borderLeft: `4px solid ${this.color}`,
          '--card-color': this.color
        }
      } else if (this.cardType === 'bordered') {
        return {
          border: `1px solid ${this.color}50`,
          borderTop: `3px solid ${this.color}`
        }
      }
      return {}
    }
  },
  methods: {
    formatNumber(num) {
      return new Intl.NumberFormat('zh-CN').format(num)
    }
  }
}
</script>

<style lang="scss" scoped>
.card-container {
  background-color: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  height: 100%;
  position: relative;
  overflow: hidden;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--card-color, #1890ff), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
  }
}

.card-hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  
  &::before {
    opacity: 1;
  }
  
  .count-number {
    transform: scale(1.05);
  }
  
  .card-decoration {
    transform: scale(1.1);
  }
  
  .title-icon {
    transform: rotate(360deg);
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #8c8c8c;
  font-weight: 500;
  margin-bottom: 16px;
  position: relative;
  z-index: 1;
  
  .title-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .title-icon {
    font-size: 20px;
    color: var(--card-color, #1890ff);
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .title {
    font-size: 16px;
    transition: color 0.3s ease;
  }
  
  .info-icon {
    cursor: pointer;
    transition: all 0.3s ease;
    
    &:hover {
      transform: scale(1.2);
    }
  }
}

.card-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 15px 0;
  position: relative;
  z-index: 1;
}

.count-wrapper {
  display: flex;
  align-items: baseline;
  justify-content: center;
  position: relative;
}

.count-number {
  font-size: 38px;
  font-weight: 600;
  margin-right: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
  letter-spacing: 0.5px;
  line-height: 1.2;
  position: relative;
  
  &::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--card-color, #1890ff), transparent);
    transform: scaleX(0);
    transition: transform 0.3s ease;
  }
}

.card-hover .count-number::after {
  transform: scaleX(1);
}

.count-trend {
  font-size: 15px;
  display: flex;
  align-items: center;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 12px;
  transition: all 0.3s ease;
  
  i {
    margin-right: 4px;
  }
}

.trend-up {
  color: #36B37E;
  background-color: rgba(54, 179, 126, 0.1);
}

.trend-down {
  color: #FF5630;
  background-color: rgba(255, 86, 48, 0.1);
}

.card-footer {
  border-top: 1px solid #f0f0f0;
  padding-top: 16px;
  padding-bottom: 4px;
  font-size: 14px;
  color: #595959;
  position: relative;
  z-index: 1;
  transition: all 0.3s ease;
}

.footer-feishu {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.footer-item {
  display: flex;
  flex-direction: column;
  flex: 1;
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-2px);
  }
}

.footer-label {
  font-size: 12px;
  color: #8F959E;
  margin-bottom: 6px;
  font-weight: 400;
  transition: color 0.3s ease;
  display: flex;
  align-items: center;
  gap: 4px;
  
  i {
    font-size: 14px;
  }
}

.footer-value-wrapper {
  display: flex;
  align-items: center;
  transition: all 0.3s ease;
}

.footer-value {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.2px;
  margin-right: 4px;
  transition: all 0.3s ease;
}

.footer-divider {
  width: 1px;
  height: 28px;
  background-color: #E8E8E8;
  margin: 0 20px;
  transition: all 0.3s ease;
}

.card-decoration {
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle at top right, var(--card-color, #1890ff) 0%, transparent 70%);
  opacity: 0.1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}

.card-pattern {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.05) 1px, transparent 0),
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.05) 1px, transparent 0);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  opacity: 0.1;
  z-index: 0;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.card-hover .card-decoration {
  animation: pulse 2s infinite;
}

@media screen and (max-width: 768px) {
  .card-container {
    padding: 15px;
  }
  
  .count-number {
    font-size: 32px;
  }
  
  .count-trend {
    font-size: 13px;
  }
  
  .footer-feishu {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .footer-divider {
    display: none;
  }
  
  .footer-item {
    margin-bottom: 8px;
  }
}
</style>
  